package com.fusion.core.settings;

import static com.fusion.core.CoreSubsystem.KB;

import com.fusion.launchers.OSInfo;

import java.io.File;

/**
 * @author SwethaShivakumar 
 * Project: fusion
 * Date: Mar 15, 2009
 * URL: http://fusionwiki.co.cc
 * Mail Me At: shiva@fusionproject.co.cc
 */
public class Internal extends SettingClass {
    private static final String CURRENT_DIRECTORY;
    private static final String USER_DIRECTORY;
    static {
    }

	static { 
		if (OSInfo.isLinux()) { 
			USER_DIRECTORY = System.getProperty("user.home")+"/.fusion/";
			CURRENT_DIRECTORY = USER_DIRECTORY;
		} else {
	        String s = new File(".").getAbsoluteFile().toString();
	        if (s.endsWith(".")) s = s.substring(0, s.length()-1);
	        CURRENT_DIRECTORY = s;
	        USER_DIRECTORY = "";
		}
	}

    
    private Integer tempcleareddups=0;

	private String filedatabasefile = USER_DIRECTORY+"data/share.dat"; 
	private String filedatabaseindexfile = USER_DIRECTORY+"data/share.idx"; 
	private String downloadquefile = USER_DIRECTORY+"data/downloads.dat"; 
	private String corestatefile = USER_DIRECTORY+"data/core.dat"; 


    private String downloadfolder = CURRENT_DIRECTORY+"downloads";
    private String cachefolder = CURRENT_DIRECTORY+"cache";
    private String keystorefilename = CURRENT_DIRECTORY+"me.ks";

    private Integer reconnectinterval = 60*10;
    private Integer connectFriendInterval = 1;
    private Integer sharemanagercycle = 30;
    private Integer sharemanagercyclewithfilesystemeventsactive = 60*2;
    private Integer maxdownloadconnections=10;
    private Integer recordoutspeed=0, recordinspeed=0;
    private Integer totalmegabytesdownloaded =0, totalmegabytesuploaded =0;
    private Integer connectionkeepaliveinterval=60;
    private Integer numberofblockstopipeline=2;

    private Integer usedirectbuffers=1; // Should direct nio buffers be used? 0=no 1=yes   - does no performance gain but it looks better in Task Manager, when looking at memory usage, not sure if the actual memory usage is better

    private Integer restartEveryXHours=4; //this one only works on windows right now

    private Long lastnaggedaboutinvitingafriend;
    private Integer hastriedtoinviteafriend;
    private Integer hasneverdownloadedafile=1;

    private Integer enablesupportfornonenglishcharacters=0;

    private Integer alwaysautomaticallyconnecttoallfriendsoffriend=0;

    private Integer invitationmayonlybeusedonce=1;

    private Integer secondstoaway=60*5;

    private String chipersuite=""; //user defined chipher suite, none by default

    private Integer encryption=0; // 0: TranslationCryptoLayer 1: SSLCryptoLayer

    private Integer daysnotconnectedwhenold=7*2; //after three weeks of disconnection from a friend hes concidered old

    private Integer alwaysallowfriendstoconnect=1;
    private Integer alwaysallowfriendsoffriendstoconnecttome=1;
    private Integer automaticallydenyallinvitations=0;

    private Integer showpublicchatmessagesintray=1;
    private Integer showprivatechatmessagesintray=1;
    private Integer showsystemmessagesintray=1;

    private Integer rescanSharewhenFusionStarts=1;

    private Integer minimumtimebetweeninvitations = 60*24*2; //in minutes

    /** Be polite when running on XP sp2 wich only allows 10 pending tcp/ip connections
     * before stopping the network stack. Set to 8 to be on the safe side. */
    private Integer maxpendingconnections = 8;

    private Integer hashspeedinmbpersecond=3; //when in background mode

    private Integer sosendbuf=-1, soreceivebuf=-1;
    private Integer discwritebuffer=256*KB, //one instance of this one per download
            socketsendbuffer=256*KB; //one instance per download
    private Integer socketreadbuffer=256*KB; //only one instance of this one - at the network layer
    private Integer maximumFusionPacketSize=32*KB;

    private Integer politehashingwaittimeinminutes=10;
    private Integer politehashingintervalingigabytes=50;

    private Integer maxfileexpandinblocks=50; //don't exceed file system size of file we're downloading to by more than this number
    //This is here because if we download the last block of a 4Gb file we seek to 4Gb into
    //an empry file. This makes XP grind to a halt. 100 means expand 100mb per block at most

    private Integer uploadthrottle=0; //zero to disable

    private String serverlistenip = "";
    
    private Integer enableiprules=0;

    public Internal() {
    }

    public Internal(Integer reconnectinterval) {
        this.reconnectinterval = reconnectinterval;
    }

    public Integer getReconnectinterval() {
        return reconnectinterval;
    }

    public void setReconnectinterval(Integer reconnectinterval) {
        this.reconnectinterval = reconnectinterval;
    }

    public Integer getSharemanagercycle() {
        return sharemanagercycle;
    }

    public void setSharemanagercycle(Integer sharemanagercycle) {
        this.sharemanagercycle = sharemanagercycle;
    }

    public String getFiledatabasefile() {
        return filedatabasefile;
    }

    public void setFiledatabasefile(String filedatabasefile) {
        this.filedatabasefile = filedatabasefile;
    }

    public String getDownloadfolder() {
        return downloadfolder;
    }

    public void setDownloadfolder(String downloadfolder) {
        this.downloadfolder = downloadfolder;
    }

    public String getCachefolder() {
        return cachefolder;
    }

    public void setCachefolder(String cachefolder) {
        this.cachefolder = cachefolder;
    }

    public Integer getMaxdownloadconnections() {
        return maxdownloadconnections;
    }

    public void setMaxdownloadconnections(Integer maxdownloadconnections) {
        this.maxdownloadconnections = maxdownloadconnections;
    }

    public Integer getRecordoutspeed() {
        return recordoutspeed;
    }

    public void setRecordoutspeed(Integer recordoutspeed) {
        this.recordoutspeed = recordoutspeed;
    }

    public Integer getRecordinspeed() {
        return recordinspeed;
    }

    public void setRecordinspeed(Integer recordinspeed) {
        this.recordinspeed = recordinspeed;
    }

    public Integer getConnectionkeepaliveinterval() {
        return connectionkeepaliveinterval;
    }

    public void setConnectionkeepaliveinterval(Integer connectionkeepaliveinterval) {
        this.connectionkeepaliveinterval = connectionkeepaliveinterval;
    }

    public Integer getSosendbuf() {
        return sosendbuf;
    }

    public void setSosendbuf(Integer sosendbuf) {
        this.sosendbuf = sosendbuf;
    }

    public Integer getSoreceivebuf() {
        return soreceivebuf;
    }

    public void setSoreceivebuf(Integer soreceivebuf) {
        this.soreceivebuf = soreceivebuf;
    }

    public Integer getNumberofblockstopipeline() {
        return numberofblockstopipeline;
    }

    public void setNumberofblockstopipeline(Integer numberofblockstopipeline) {
        this.numberofblockstopipeline = numberofblockstopipeline;
    }

    public Integer getDiscwritebuffer() {
        return discwritebuffer;
    }

    public void setDiscwritebuffer(Integer discwritebuffer) {
        this.discwritebuffer = discwritebuffer;
    }

    public Integer getSocketsendbuffer() {
        return socketsendbuffer;
    }

    public void setSocketsendbuffer(Integer socketsendbuffer) {
        this.socketsendbuffer = socketsendbuffer;
    }

    public Integer getSocketreadbuffer() {
        return socketreadbuffer;
    }

    public void setSocketreadbuffer(Integer socketreadbuffer) {
        this.socketreadbuffer = socketreadbuffer;
    }

    public Integer getMaximumFusionPacketSize() {
        return maximumFusionPacketSize;
    }

    public void setMaximumFusionPacketSize(Integer maximumFusionPacketSize) {
        this.maximumFusionPacketSize = maximumFusionPacketSize;
    }

    public Integer getPolitehashingwaittimeinminutes() {
        return politehashingwaittimeinminutes;
    }

    public void setPolitehashingwaittimeinminutes(Integer politehashingwaittimeinminutes) {
        this.politehashingwaittimeinminutes = politehashingwaittimeinminutes;
    }

    public Integer getPolitehashingintervalingigabytes() {
        return politehashingintervalingigabytes;
    }

    public void setPolitehashingintervalingigabytes(Integer politehashingintervalingigabytes) {
        this.politehashingintervalingigabytes = politehashingintervalingigabytes;
    }

    //don't exceed file system size of file we're downloading to by more than this number
    //This is here because if we downloads the last block of a 4Gb file we seek to 4Gb into
    //an empry file. This makes XP grind to a halt. 100 means expan 100mb per block at most
    public Integer getMaxfileexpandinblocks() {
        return maxfileexpandinblocks;
    }

    public void setMaxfileexpandinblocks(Integer maxfileexpandinblocks) {
        this.maxfileexpandinblocks = maxfileexpandinblocks;
    }

    public Integer getUploadthrottle() {
        return uploadthrottle;
    }

    public void setUploadthrottle(Integer uploadthrottle) {
        this.uploadthrottle = uploadthrottle;
    }

    public Integer getHashspeedinmbpersecond() {
        return hashspeedinmbpersecond;
    }

    public void setHashspeedinmbpersecond(Integer hashspeedinmbpersecond) {
        this.hashspeedinmbpersecond = hashspeedinmbpersecond;
    }

    public Integer getConnectFriendInterval() {
        return connectFriendInterval;
    }

    public void setConnectFriendInterval(Integer connectFriendInterval) {
        this.connectFriendInterval = connectFriendInterval;
    }

    public String getCorestatefile() {
        return corestatefile;
    }

    public void setCorestatefile(String corestatefile) {
        this.corestatefile = corestatefile;
    }

    public Integer getMaxpendingconnections() {
        return maxpendingconnections;
    }

    public void setMaxpendingconnections(Integer maxpendingconnections) {
        this.maxpendingconnections = maxpendingconnections;
    }

    public Integer getMinimumtimebetweeninvitations() {
        return minimumtimebetweeninvitations;
    }

    public void setMinimumtimebetweeninvitations(Integer minimumtimebetweeninvitations) {
        this.minimumtimebetweeninvitations = minimumtimebetweeninvitations;
    }

    public Integer getTempcleareddups() {
        return tempcleareddups;
    }

    public void setTempcleareddups(Integer tempcleareddups) {
        this.tempcleareddups = tempcleareddups;
    }

    public Integer getAlwaysallowfriendstoconnect() {
        return alwaysallowfriendstoconnect;
    }

    public void setAlwaysallowfriendstoconnect(Integer alwaysallowfriendstoconnect) {
        this.alwaysallowfriendstoconnect = alwaysallowfriendstoconnect;
    }

    public Integer getDaysnotconnectedwhenold() {
        return daysnotconnectedwhenold;
    }

    public void setDaysnotconnectedwhenold(Integer daysnotconnectedwhenold) {
        this.daysnotconnectedwhenold = daysnotconnectedwhenold;
    }

    public String getKeystorefilename() {
        return keystorefilename;
    }

    public void setKeystorefilename(String keystorefilename) {
        this.keystorefilename = keystorefilename;
    }

    public Integer getUsedirectbuffers() {
        return usedirectbuffers;
    }

    public void setUsedirectbuffers(Integer usedirectbuffers) {
        this.usedirectbuffers = usedirectbuffers;
    }

    public Integer getEncryption() {
        return encryption;
    }

    public void setEncryption(Integer encryption) {
        this.encryption = encryption;
    }

    public String getChiphersuite() {
        return chipersuite;
    }

    public void setChipersuite(String chipersuite) {
        this.chipersuite = chipersuite;
    }

    public Integer getAlwaysallowfriendsoffriendstoconnecttome() {
        return alwaysallowfriendsoffriendstoconnecttome;
    }

    public void setAlwaysallowfriendsoffriendstoconnecttome(Integer alwaysallowfriendsoffriendstoconnecttome) {
        this.alwaysallowfriendsoffriendstoconnecttome = alwaysallowfriendsoffriendstoconnecttome;
    }

    public String getServerlistenip() {
        return serverlistenip;
    }

    public void setServerlistenip(String serverlistenip) {
        this.serverlistenip = serverlistenip;
    }

    public Integer getTotalmegabytesdownloaded() {
        return totalmegabytesdownloaded;
    }

    public void setTotalmegabytesdownloaded(Integer totalmegabytesdownloaded) {
        this.totalmegabytesdownloaded = totalmegabytesdownloaded;
    }

    public Integer getTotalmegabytesuploaded() {
        return totalmegabytesuploaded;
    }

    public void setTotalmegabytesuploaded(Integer totalmegabytesuploaded) {
        this.totalmegabytesuploaded = totalmegabytesuploaded;
    }

    public String getFiledatabaseindexfile() {
        return filedatabaseindexfile;
    }

    public String getDownloadquefile() {
        return downloadquefile;
    }

    public void setFiledatabaseindexfile(String filedatabaseindexfile) {
        this.filedatabaseindexfile = filedatabaseindexfile;
    }

    public void setDownloadquefile(String downloadquefile) {
        this.downloadquefile = downloadquefile;
    }

    public Integer getShowpublicchatmessagesintray() {
        return showpublicchatmessagesintray;
    }

    public void setShowpublicchatmessagesintray(Integer showpublicchatmessagesintray) {
        this.showpublicchatmessagesintray = showpublicchatmessagesintray;
    }

    public Integer getShowprivatechatmessagesintray() {
        return showprivatechatmessagesintray;
    }

    public void setShowprivatechatmessagesintray(Integer showprivatechatmessagesintray) {
        this.showprivatechatmessagesintray = showprivatechatmessagesintray;
    }

    public Integer getShowsystemmessagesintray() {
        return showsystemmessagesintray;
    }

    public void setShowsystemmessagesintray(Integer showsystemmessagesintray) {
        this.showsystemmessagesintray = showsystemmessagesintray;
    }

    public Integer getSecondstoaway() {
        return secondstoaway;
    }

    public void setSecondstoaway(Integer secondstoaway) {
        this.secondstoaway = secondstoaway;
    }

    public Integer getInvitationmayonlybeusedonce() {
        return invitationmayonlybeusedonce;
    }

    public void setInvitationmayonlybeusedonce(Integer invitationmayonlybeusedonce) {
        this.invitationmayonlybeusedonce = invitationmayonlybeusedonce;
    }


    public Integer getSharemanagercyclewithfilesystemeventsactive() {
        return sharemanagercyclewithfilesystemeventsactive;
    }

    public void setSharemanagercyclewithfilesystemeventsactive(Integer sharemanagercyclewithfilesystemeventsactive) {
        this.sharemanagercyclewithfilesystemeventsactive = sharemanagercyclewithfilesystemeventsactive;
    }

    public Integer getRestartEveryXHours() {
        return restartEveryXHours;
    }

    public void setRestartEveryXHours(Integer restartEveryXHours) {
        this.restartEveryXHours = restartEveryXHours;
    }

    public Long getLastnaggedaboutinvitingafriend() {
        return lastnaggedaboutinvitingafriend;
    }

    public void setLastnaggedaboutinvitingafriend(Long lastnaggedaboutinvitingafriend) {
        this.lastnaggedaboutinvitingafriend = lastnaggedaboutinvitingafriend;
    }

    public Integer getHastriedtoinviteafriend() {
        return hastriedtoinviteafriend;
    }

    public void setHastriedtoinviteafriend(Integer hastriedtoinviteafriend) {
        this.hastriedtoinviteafriend = hastriedtoinviteafriend;
    }

    public Integer getHasneverdownloadedafile() {
        return hasneverdownloadedafile;
    }

    public void setHasneverdownloadedafile(Integer hasneverdownloadedafile) {
        this.hasneverdownloadedafile = hasneverdownloadedafile;
    }


    public Integer getRescansharewhenfusionstarts() {
        return rescanSharewhenFusionStarts;
    }

    public void setRescansharewhenfusionstarts(Integer rescanShareWhenFusionStarts) {
        this.rescanSharewhenFusionStarts = rescanShareWhenFusionStarts;
    }

    public Integer getEnablesupportfornonenglishcharacters() {
        return enablesupportfornonenglishcharacters;
    }

    public void setEnablesupportfornonenglishcharacters(Integer enablesupportfornonenglishcharacters) {
        this.enablesupportfornonenglishcharacters = enablesupportfornonenglishcharacters;
    }

    public Integer getAlwaysautomaticallyconnecttoallfriendsoffriend() {
        return alwaysautomaticallyconnecttoallfriendsoffriend;
    }

    public void setAlwaysautomaticallyconnecttoallfriendsoffriend(Integer alwaysautomaticallyconnecttoallfriendsoffriend) {
        this.alwaysautomaticallyconnecttoallfriendsoffriend = alwaysautomaticallyconnecttoallfriendsoffriend;
    }
    
    public void setEnableiprules(Integer rule){
    	enableiprules= rule;
    }
    
    public Integer getEnableiprules(){
    	return enableiprules;
    }

    public Integer getAutomaticallydenyallinvitations() {
        return automaticallydenyallinvitations;
    }

    public void setAutomaticallydenyallinvitations(Integer automaticallydenyallinvitations) {
        this.automaticallydenyallinvitations = automaticallydenyallinvitations;
    }
}
